
import re
from time import sleep

from playwright.sync_api import Playwright, sync_playwright
import time
import random

from config.config import get_upload_dir_path
from model.ProConfModel import ProConfModel
from service.KeepAliveService import set_keep_alive_storage
from tools.Func import wait_for_file_content


def do_login_test() -> None:
    with sync_playwright() as playwright:
        browser = playwright.firefox.launch(headless=False)
        context = browser.new_context()
        page = context.new_page()
        page.goto("https://www.dajiajixie.com/loginReg/login",wait_until="networkidle", timeout=15000)
        page.get_by_role("textbox", name="账号").click()
        page.get_by_role("textbox", name="账号").fill("13180093138")
        page.get_by_role("textbox", name="密码").click()
        page.get_by_role("textbox", name="密码").fill("Jiaxing1919@")

        page.get_by_role("button", name="获取验证码").click()
        code=wait_for_file_content(get_upload_dir_path()+"djjx_code")

        page.get_by_role("textbox", name="验证码").fill(code)

        page.get_by_role("button", name="登 录").click()

        sleep(10)
        set_keep_alive_storage(  ProConfModel.get_by_type(8), context)

        # ---------------------
        sleep(5000)

        context.close()
        browser.close()
if __name__ == '__main__':
    do_login_test()